<template>
    <view class="memberTransfer">
			<!-- <uni-nav-bar color="#000" background-color="#fff" :status-bar="true" left-icon="arrowleft" left-text="会员转会" title="会员转会" @clickLeft="back" /> -->
			<view :class="nodata?'':'wrapper'">
				<view class="transfer_cell" v-for="(item,index) in transferData" :key="index" v-if="nodata==false">
					<view class="transfer_header">
						<view class="">
							<text>{{item.mem_name?item.mem_name:''}}</text>
							<text class="sex">({{item.gender?item.gender:''}}</text>
							<text class="type_name">{{item.type_name?item.type_name:""}})</text>
						</view>
						<view class="status">
							<uni-tag
								:text="item.status['text']" 
								size="small" 
								:inverted="true" 
								:circle="true"
								:type="item.status['value']">
							</uni-tag>
						</view>
					</view>
					<view class="transfer_content">
						<view class="cell">
							证件号：{{item.idCard?item.idCard:""}}
						</view>
						<view class="cell">
							申请机构：{{item.transfer_in_org_name?item.transfer_in_org_name:""}}
						</view>
						<view class="cell">
							申请时间：{{item.time?item.time:""}}
						</view>
						<view class="btns" v-if="item.transfer_state==1">
						<!-- <view class="btns"> -->
							<!-- <view class="btn no_agree" @tap.stop="noAgree(item.mem_name,item.transfer_guid)">
								拒绝
							</view>
							<view class="btn agree" @tap.stop="agree(item.mem_name,item.transfer_guid)">
								同意
							</view> -->
							<view class="btn agree" @tap.stop="toTransferAudit(item.transfer_guid,item.idCard)">
								去审核
							</view>
						</view>
					</view>
				</view>
				<uni-load-more
					v-if="isLoading"
					:status="loadingStatus" 
					iconType='auto' 
					:showIcon=true>
					</uni-load-more>
				<view class="nodata" v-if="nodata">
					<view class="msfont ms-wushuju">			
					</view>
					<view class="">
						当前没有可操作的申请
					</view>
				</view>
			</view>
			<view class="footer">
				<button  size="mini" class="btns bWhite" @tap.stop="toTransferRecord">转会记录</button>
				<button  size="mini" class="btns bBlue" @tap.stop="toTransferApplication">申请转会</button>
			</view>
    </view>
</template>
<script>
	import uniTag from "@/components/uni-tag/uni-tag.vue";
	import {transferList,rankExtent,transferApplication} from "@/common/api.js";
	import uniCheck from "@/components/uni-event/uni-check.vue";
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	export default {
		name: "memberTransfer",
		data() {
			return {
				 page:{
					 pageSize:7,
					 currentPage:1
				 },
				 transferData:[],
				 rank_arr:[],
				 showPopup:false,
				 popupData:{},
				 isAgree:false,
				 type:"transfer",
				 guid:"",
				 nodata:false,
				 isLoading:false,
				 loadingStatus:"loading"
			};
		},
		components: {
			uniTag,
			uniCheck,
			uniLoadMore,
			uniNavBar
		},
		onReachBottom() {
			var _this=this;
			_this.moreTransferData()
		},
		onLoad() {
			var _this=this;
			_this.getRankExtent()
		},
		onPullDownRefresh(){
			var _this=this;
			_this.page.currentPage=1;
			_this.transferData=[];
			_this.getTransferData();
			setTimeout(function(){
				uni.stopPullDownRefresh()
			},1000)
		},
		methods: {
			back(){
				uni.navigateTo({
					url:'/pages/home/index'
				})
			},
			getTransferData(){
				var _this=this,data={};
				data={
					type:2,
					page:_this.page.currentPage,
					pageSize:_this.page.pageSize,
					keywords:""
				}
				transferList(data).then(function(res){
					var e=res.data;
					if(e.errcode==0){
						// console.log(e.data,_this.rank_arr)
						e.data.map(function(item,index){
							item.gender=item.sex=="0"?"男":"女"
							item.time=item.create_time!=null?item.create_time.slice(0,4)+"年"+item.create_time.slice(5,7)+"月"+item.create_time.slice(8,10)+'日':"暂无"
							item.status=_this.checkState(item.transfer_state)
							_this.rank_arr.map(function(items,indexs){
								if(item.level==items.eventType_id){
									item.type_name=items.type_name
								}
							})
						})
						_this.transferData=e.data;
						_this.isLoading=Number(e.total)>_this.transferData.length?true:false;
						_this.page.currentPage+=1;
						_this.nodata=Number(e.total)==0?true:false;
					}else if(e.errcode==1000||e.errcode==1001){
						uni.removeStorageSync('token');
						uni.reLaunch({
							url:'/pages/home/welcome'
						})
					}else{
						uni.showToast({
							position: 'center',
							icon: 'none',
							title:e.msg
						});
					}
				})
			},
			moreTransferData(){
				var _this=this,data={};
				data={
					type:2,
					page:_this.page.currentPage,
					pageSize:_this.page.pageSize,
					keywords:""
				}
				transferList(data).then(function(res){
					var e=res.data;
					if(e.errcode==0){
						// console.log(e.data,_this.rank_arr)
						e.data.map(function(item,index){
							item.gender=item.sex=="0"?"男":"女"
							item.time=item.create_time!=null?item.create_time.slice(0,4)+"年"+item.create_time.slice(5,7)+"月"+item.create_time.slice(8,10)+'日':"暂无"
							item.status=_this.checkState(item.transfer_state)
							_this.rank_arr.map(function(items,indexs){
								if(item.level==items.eventType_id){
									item.type_name=items.type_name
								}
							})
						})
						_this.transferData=_this.transferData.concat(e.data);
						_this.isLoading=Number(e.total)>_this.transferData.length?true:false;
						// if(Number(e.total)>_this.transferData.length){
							_this.page.currentPage+=1;
						// }
					}else if(e.errcode==1000||e.errcode==1001){
						uni.removeStorageSync('token');
						uni.reLaunch({
							url:'/pages/home/welcome'
						})
					}else{
						uni.showToast({
							position: 'center',
							icon: 'none',
							title:e.msg
						});
					}
				})
			},
			checkState(state){
				if(state==1){
					return {text:"待处理",value:"warning"}
				}else if(state==2){
					return {text:"正常",value:"success"}
				}else if(state==4){
					return {text:"过期",value:"warning"}
				}
			},
			//获取级别范围
			getRankExtent() {
				var _this = this;
				//测试
					// _this.rankSet.itemObject.step_1.push({type_name:'1级'},{type_name:"2级"})
					// _this.rankSet.itemObject.step_2.push([{type_name:'2级'},{type_name:"1级"}],[{type_name:'3级'},{type_name:"4级"}])
					
				rankExtent().then(function(res) {
					var e = res.data;
					if (e.errcode == 0) {
						if (e.data.length > 0) {
							_this.rank_arr=e.data;
							_this.getTransferData();
						}
					}
				})
			},
			toTransferRecord(){
				uni.navigateTo({
					url:"/pages/memberTransfer/transferRecord"
				})
			},
			toTransferApplication(){
				uni.navigateTo({
					url:"/pages/memberTransfer/transferApplication"
				})
			},
			toTransferAudit(guid,idcard){
				uni.navigateTo({
					url:'/pages/memberTransfer/transferAudit?guid='+guid+"&idcard="+idcard
				})
			}
		},
	};
</script>
<style lang="scss">
	.memberTransfer {
		// width: 100%;
		// background: #fff;
	}
	.wrapper{
		margin-bottom: 100rpx;
	}
	.transfer_cell{
		margin: 24rpx;
		background: #fff;
		padding: 32rpx;
	}
	.transfer_cell:last-child{
		margin-bottom: 100rpx;
	}
	.transfer_header{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid #F1F1F2;
		.sex{
			padding-left: 20rpx;
		}
		.type_name{
			padding-left: 14rpx;
		}
		text{
			font-size: 32rpx;
		}
		.status{
			padding-left: 20rpx;
		}
	}
	.transfer_content{
		position: relative;
		margin-top: 12rpx;
		.cell{
			margin-top: 16rpx;
		}
		.btns{
			position: absolute;
			right: 0;
			bottom: 0;
			display: flex;
			flex-direction: row;
		}
		.btn{
			width: 140rpx;
			height: 56rpx;
			line-height: 56rpx;
			font-size: 28rpx;
			text-align: center;
		}
		.no_agree{
			background:rgba(255,255,255,1);
			border:2rpx solid rgba(26,102,255,1);
			opacity:1;
			border-radius:32rpx;
			color: #1A66FF;
			background: #fff;
		}
		.agree{
			background:rgba(26,102,255,1);
			border:2rpx solid rgba(26,102,255,1);
			opacity:1;
			border-radius:32rpx;
			color: #fff;
			margin-left: 16rpx;
		}
	}
	.nodata{
		position: fixed;
		top: 50%;
		left: 50%;
		margin-left: -117rpx;
		margin-top: -40%;
		.ms-wushuju{
			font-size: 150rpx;
			color: #ccc;
		}
		view:last-child{
			color: #aaa;
			text-align: center;
			margin-left: -42%;
			margin-top: -55rpx;
			font-size: 40rpx;
		}
	}
	.footer{
		position: fixed;
		bottom: 20rpx;
		display: flex;
		flex-direction: row;
		width: 100%;
		button::after{ border: none;}
		.bWhite{
			background: #fff;
			color: #1A66FF;
			border: 2rpx solid #1A66FF;
		}
		.bBlue{
			background: #1A66FF;
			color: #fff;
		}
		.btns{
			width: 47%;
		}
	}
</style>
